

export interface treeData {
    id: string;
    name: string;
    url: string;
    type: number;
    icon: string | null;
    childrenList: treeData[] | null;
}


export function filterTree(data: treeData[], types: number[]): treeData[] {
    return data.reduce<treeData[]>((acc, item) => {
        if (types.includes(item.type)) {
            const newItem: treeData = { ...item };
            if (newItem.childrenList) {
                newItem.childrenList = filterTree(newItem.childrenList, types);
                if (newItem.childrenList.length === 0) {
                    newItem.childrenList = null;
                }
            }
            acc.push(newItem);
        }
        return acc;
    }, []);
}
